package context

import (
	"strings"
)

type constant struct {
	Host        string `json:"host"`
	Scheme      string `json:"scheme"`
	Ip          string `json:"ip"`
	Domain      string `json:"domain"`
	Url         string `json:"url"`
	BaseUrl     string `json:"base_url"`
	Path        string `json:"path"`
	ResourceUrl string `json:"resource_url"`
	StaticUrl   string `json:"static_url"`
	StorageUrl  string `json:"storage_url"`
	App         string `json:"app"` // 当前app
	Controller  string `json:"controller"`
	Action      string `json:"action"`
}

var Global constant

func InitGlobal(scheme string, host string, url string, path string, ip string) {
	pathArr := strings.Split(path, "/")
	if len(pathArr) < 4 {
		pathArr = []string{"", "", "", ""}
	}
	// fmt.Println("模块：" + pathArr[1] + " 控制器：" + pathArr[2] + " 方法：" + pathArr[3])
	Global = constant{
		Host:        host,
		Scheme:      scheme,
		Ip:          ip,
		Domain:      scheme + host,
		Url:         url,
		BaseUrl:     scheme + host + path,
		Path:        path,
		ResourceUrl: scheme + host + "/resource",
		StaticUrl:   scheme + host + "/static",
		StorageUrl:  scheme + host + "/storage",
		App:         pathArr[1],
	}
}
